package com.plugins.usereflect;

import java.sql.SQLException;
import java.util.LinkedHashMap;

import org.json.JSONObject;

import com.zxy.business.Ope_DB_Cent;
import com.zxy.common.Com_Fun;
import com.zxy.common.Db_Common_InterFace;
import com.zxy.common.PooledConnection_InterFace;
import com.zxy.model.T_PROC_NAME;

//导出单表信息
public class A01_OUTTAB_IN implements com.zxy.common.ParamName_InterFace
{
	public StringBuilder	strResult		= new StringBuilder();
	public String			user_main_id			= null;
	public String			session_id		= null;
	public String			param_name		= "";
	//表名
	public String			param_value1	= null;
	//MAIN_ID主键集合
	public String			param_value2	= null;
	//数据源 ID
	public String			param_value3	= null;
	public String			param_value4	= null;
	public String			param_value5	= null;
	public String			param_value6	= null;
	public String			param_value7	= null;
	public String			param_value8	= null;
	public String			param_value9	= null;
	public String			param_value10	= null;
	
	public void init_start()
	{
		JSONObject jsoR = new JSONObject(new LinkedHashMap());
		JSONObject jso = new JSONObject(new LinkedHashMap());
		try
		{
			Ope_DB_Cent odc = new Ope_DB_Cent();
			String strSql = "";
			String strWhere = " where ";
			if(java.util.Objects.equals(this.param_value2,""))
					strWhere += "1=1";
			else{
				strWhere += "MAIN_ID in (";
				boolean bFlag = false;
				for(String strM : this.param_value2.split(",")){
					if(!java.util.Objects.equals(strM,"")){
						if(bFlag)
							strWhere += ",";
						strWhere += "'"+strM+"'";
						bFlag = true;
					}					
				}
				strWhere += ")";
			}		
			//特殊的表处理含主从表及关联表
			if(java.util.Objects.equals(this.param_value1,"特殊的表处理")){
				
			}
			else if(java.util.Objects.equals(this.param_value1,"menu_content")){
				String temSql = "select * from menu_info where main_id in (SELECT MENU_ID FROM menu_content "
						+strWhere+") order by S_SORT";
				jso.put("menu_info",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere));
			}
			else if(java.util.Objects.equals(this.param_value1,"menu_info")){
				String temSql = "select * from menu_group where main_id in (SELECT GROUP_ID FROM menu_info "
						+strWhere+") order by S_SORT";
				jso.put("menu_group",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere+" order by S_SORT"));
			}
			else if(java.util.Objects.equals(this.param_value1,"t_sub_user")){				
				String temSql = "select * from t_sub_sys where main_id in (SELECT sub_id FROM t_sub_user "
						+strWhere+") order by S_SORT";
				jso.put("t_sub_sys",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere+" order by S_SORT"));
			}		
			else if(java.util.Objects.equals(this.param_value1,"t_page_item")){
				
				String temSql = "select * from t_page_info where main_id in (SELECT page_id FROM t_page_item "
						+strWhere+") order by S_SORT";
				jso.put("t_page_info",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				temSql = "select * from t_proc_name where main_id in (SELECT proc_id FROM t_page_item "
						+strWhere+") order by S_SORT";
				jso.put("t_proc_name",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere+" order by S_SORT"));
			}
			else if(java.util.Objects.equals(this.param_value1,"t_single_table")){
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere+" order by S_SORT"));
				
				String temSql = "select * from t_single_expand where TABLE_ID in (SELECT MAIN_ID FROM t_single_table "
						+strWhere+")";
				jso.put("t_single_expand",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				temSql = "select * from t_table_column where TABLE_ID in (SELECT MAIN_ID FROM t_single_table "
						+strWhere+")";
				jso.put("t_table_column",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));

				temSql = "select * from t_table_column where TABLE_ID in (SELECT MAIN_ID FROM t_single_table "
						+strWhere+")";
				jso.put("t_table_column",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
				
				temSql = "select * from t_column_expand where COLUMN_ID in (select MAIN_ID from t_table_column where "
						+ "TABLE_ID in (SELECT MAIN_ID FROM t_single_table "
						+strWhere+"))";
				jso.put("t_column_expand",odc.SqlToJson(Integer.valueOf(this.param_value3),temSql));
			}
			//单一表处理
			else{
				strSql = "select * from "+this.param_value1;
				jso.put(this.param_value1,odc.SqlToJson(Integer.valueOf(this.param_value3),strSql+strWhere));
			}
			
			jsoR.put(this.param_name,jso);
			this.strResult.delete(0,this.strResult.length());
			this.strResult.append(jsoR.toString());
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
		}
	}

	/**
	 * @return strResult
	 */
	public StringBuilder getStrResult()
	{
		return strResult;
	}

	/**
	 * @param strResult 要设置的 strResult
	 */
	public void setStrResult(StringBuilder strResult)
	{
		this.strResult = strResult;
	}

	/**
	 * @return user_main_id
	 */
	public String getUser_main_id()
	{
		return user_main_id;
	}

	/**
	 * @param user_main_id 要设置的 user_main_id
	 */
	public void setUser_main_id(String user_main_id)
	{
		this.user_main_id = user_main_id;
	}

	/**
	 * @return session_id
	 */
	public String getSession_id()
	{
		return session_id;
	}

	/**
	 * @param session_id 要设置的 session_id
	 */
	public void setSession_id(String session_id)
	{
		this.session_id = session_id;
	}

	/**
	 * @return param_name
	 */
	public String getParam_name()
	{
		return param_name;
	}

	/**
	 * @param param_name 要设置的 param_name
	 */
	public void setParam_name(String param_name)
	{
		this.param_name = param_name;
	}

	/**
	 * @return param_value1
	 */
	public String getParam_value1()
	{
		return param_value1;
	}

	/**
	 * @param param_value1 要设置的 param_value1
	 */
	public void setParam_value1(String param_value1)
	{
		this.param_value1 = param_value1;
	}

	/**
	 * @return param_value2
	 */
	public String getParam_value2()
	{
		return param_value2;
	}

	/**
	 * @param param_value2 要设置的 param_value2
	 */
	public void setParam_value2(String param_value2)
	{
		this.param_value2 = param_value2;
	}

	/**
	 * @return param_value3
	 */
	public String getParam_value3()
	{
		return param_value3;
	}

	/**
	 * @param param_value3 要设置的 param_value3
	 */
	public void setParam_value3(String param_value3)
	{
		this.param_value3 = param_value3;
	}

	/**
	 * @return param_value4
	 */
	public String getParam_value4()
	{
		return param_value4;
	}

	/**
	 * @param param_value4 要设置的 param_value4
	 */
	public void setParam_value4(String param_value4)
	{
		this.param_value4 = param_value4;
	}

	/**
	 * @return param_value5
	 */
	public String getParam_value5()
	{
		return param_value5;
	}

	/**
	 * @param param_value5 要设置的 param_value5
	 */
	public void setParam_value5(String param_value5)
	{
		this.param_value5 = param_value5;
	}

	/**
	 * @return param_value6
	 */
	public String getParam_value6()
	{
		return param_value6;
	}

	/**
	 * @param param_value6 要设置的 param_value6
	 */
	public void setParam_value6(String param_value6)
	{
		this.param_value6 = param_value6;
	}

	/**
	 * @return param_value7
	 */
	public String getParam_value7()
	{
		return param_value7;
	}

	/**
	 * @param param_value7 要设置的 param_value7
	 */
	public void setParam_value7(String param_value7)
	{
		this.param_value7 = param_value7;
	}

	/**
	 * @return param_value8
	 */
	public String getParam_value8()
	{
		return param_value8;
	}

	/**
	 * @param param_value8 要设置的 param_value8
	 */
	public void setParam_value8(String param_value8)
	{
		this.param_value8 = param_value8;
	}

	/**
	 * @return param_value9
	 */
	public String getParam_value9()
	{
		return param_value9;
	}

	/**
	 * @param param_value9 要设置的 param_value9
	 */
	public void setParam_value9(String param_value9)
	{
		this.param_value9 = param_value9;
	}

	/**
	 * @return param_value10
	 */
	public String getParam_value10()
	{
		return param_value10;
	}

	/**
	 * @param param_value10 要设置的 param_value10
	 */
	public void setParam_value10(String param_value10)
	{
		this.param_value10 = param_value10;
	}
}
